
<script type="text/javascript" charset="utf-8">

		var computerroom_id;
		var rackspace_id;
		var hardware_manufacturer;
		var hardware_name;
		var hardwarestatus_id;
		var department_id;
		var departmentproject_id;
		var applicationtype_id;
		$(function(){
			
			computerroom_id = $('#computerroom_id').combobox({
				url:'/idcpost/computerroominfo',
				valueField:'id',
				textField:'cr_name',
				editable:false,
				panelHeight:'150',
				required:true,
				onSelect:function(record){
					rackspace_id.combobox({
						url:'/idcpost/rackspaceinfo/'+record.id,
						valueField:'id',
						textField:'rackspace_name',
						editable:false,
						panelHeight:'150',
						required:true
					}).combobox('clear');
					//rackspace_id.combobox().combobox('clear');
				}
			});

			rackspace_id = $('#rackspace_id').combobox({
				valueField:'id',
				textField:'rackspace_name',
				editable:false,
				required:true,
			});
			
			hardware_manufacturer = $('#hardware_manufacturer').combobox({
				url:'/devicespost/hardware_manufacturerinfo',
				valueField:'id',
				textField:'hardware_manufacturer',
				editable:false,
				panelHeight:'150',
				required:true,
				onSelect:function(record){
					hardware_name.combobox({
						url:'/devicespost/hardware_nameinfo/'+record.hardware_manufacturer,
						valueField:'id',
						textField:'hardware_name',
						editable:false,
						panelHeight:'150',
						required:true
					}).combobox('clear');
					//rackspace_id.combobox().combobox('clear');
				}
			});

			hardware_name = $('#hardware_name').combobox({
				valueField:'id',
				textField:'hardware_name',
				editable:false,
				required:true,
			});
			
			//状态信息
			hardwarestatus_id = $('#hardwarestatus_id').combobox({
				url:'/devicespost/hardwarestatusinfo',
				valueField:'id',
				textField:'hardwarestatus_name',
				editable:false,
				required:true,
				panelHeight:'150',
				onSelect:function(record){  
				   $.ajax({            
						  type:"POST",   //post提交方式默认是get
						  url:"/devicespost/hardwarestatus_hasapp", 
						  dataType:"json",
						  data:{hardwarestatus_id:record.id},        
						  error:function(request) {      // 设置表单提交出错                 
							  alert("请求出错");  //登录错误提示信息
						  },
						  success:function(data) {
							  //网络设备就显示tr
							  if(data.hasapp == 1){
								  //document.getElementById("tr_hardware_port_num").style.display="inline";
								  $("#tr_applicationtype_id").show();
								  department_id = $('#department_id').combobox({
										url:'/operationpost/departmentinfo',
										valueField:'id',
										textField:'department_name',
										editable:false,
										required:true,
										panelHeight:'150',
										onSelect:function(record){
											departmentproject_id.combobox({
												url:'/operationpost/departmentprojectinfo/'+record.id,
												valueField:'id',
												textField:'dp_name',
												editable:false,
												panelHeight:'150',
												required:true,
												onSelect:function(record){
													applicationtype_id.combobox({
														url:'/operationpost/applicationtypeinfo/'+record.id,
														valueField:'id',
														textField:'applicationtype_name',
														editable:false,
														panelHeight:'150',
														required:true
													}).combobox('clear');
												}
											}).combobox('clear');
											applicationtype_id.combobox().combobox('clear');
										}
								  }).combobox('clear');

							  }else{
								  //document.getElementById("tr_hardware_port_num").style.display="none";
								  $("#tr_applicationtype_id").hide();
								  $('#department_id').combobox({
										required: false,
									}).combobox('clear');
								  $('#departmentproject_id').combobox({
										required: false,
									}).combobox('clear');
								  $('#applicationtype_id').combobox({
										required: false,
									}).combobox('clear');
								  }
						  }         
					}); 
				}
			});

			departmentproject_id = $('#departmentproject_id').combobox({
				valueField:'id',
				textField:'dp_name',
				editable:false,
				required:true,
			});
			
			applicationtype_id = $('#applicationtype_id').combobox({
				valueField:'id',
				textField:'applicationtype_name',
				editable:false,
				required:true,
			});
			
			$(".server_cpu_add").click(function(){
				var newTr=$("<tr></tr>");
				newTr.html($(this).parents("tr").html());
				newTr.insertAfter($(this).parents('tr'));
				newTr.find(".server_cpu_add").replaceWith("<a class='server_cpu_del'><img alt='删除' src='{{=url_for_static('images/del.png')}}' style='border: 0px; width: 16px; height: 16px' />删除</a>");
				//移除方法
				$(".server_cpu_del").click(function(){
					$(this).parents("tr").remove();
				});
			});
			
			$(".server_mem_add").click(function(){
				var newTr=$("<tr></tr>");
				newTr.html($(this).parents("tr").html());
				newTr.insertAfter($(this).parents('tr'));
		
				newTr.find(".server_mem_add").replaceWith("<a class='server_mem_del'><img alt='删除' src='{{=url_for_static('images/del.png')}}' style='border: 0px; width: 16px; height: 16px' />删除</a>");
				//移除方法
				$(".server_mem_del").click(function(){
					$(this).parents("tr").remove();
				});
			});
			
			$(".server_power_add").click(function(){
				var newTr=$("<tr></tr>");
				newTr.html($(this).parents("tr").html());
				newTr.insertAfter($(this).parents('tr'));
		
				newTr.find(".server_power_add").replaceWith("<a class='server_power_del'><img alt='删除' src='{{=url_for_static('images/del.png')}}' style='border: 0px; width: 16px; height: 16px' />删除</a>");
				//移除方法
				$(".server_power_del").click(function(){
					$(this).parents("tr").remove();
				});
			});
			
			$(".server_disk_add").click(function(){
				var newTr=$("<tr></tr>");
				newTr.html($(this).parents("tr").html());
				newTr.insertAfter($(this).parents('tr'));
		
				newTr.find(".server_disk_add").replaceWith("<a class='server_disk_del'><img alt='删除' src='{{=url_for_static('images/del.png')}}' style='border: 0px; width: 16px; height: 16px' />删除</a>");
				//移除方法
				$(".server_disk_del").click(function(){
					$(this).parents("tr").remove();
				});
			});
			
			$(".server_ethernet_add").click(function(){
				var newTr=$("<tr></tr>");
				newTr.html($(this).parents("tr").html());
				newTr.insertAfter($(this).parents('tr'));
		
				newTr.find(".server_ethernet_add").replaceWith("<a class='server_ethernet_del'><img alt='删除' src='{{=url_for_static('images/del.png')}}' style='border: 0px; width: 16px; height: 16px' />删除</a>");
				//移除方法
				$(".server_ethernet_del").click(function(){
					$(this).parents("tr").remove();
				});
			});
			
			//保修状态，过保就隐藏过保日期
			$('#server_warranty').combobox({
				valueField: 'id',
				textField: 'value',
				data: [{
					id: '0',
					value: '过保'
				},{
					id: '1',
					value: '在保'
				}],
				required: true,
				panelHeight:'auto',
				onSelect:function(record){
					if(record.id=='0'){
						$("#tr_server_warranty_datetime").hide();
						$('#server_warranty_datetime').datetimebox({
							required: false,
						}).datetimebox('clear');
					}else{
						$("#tr_server_warranty_datetime").show();
						$('#server_warranty_datetime').datetimebox({
							required: true,
						}).datetimebox('clear');
					}
				}
				
			});
			
			$('#server_cpu').validatebox({
				required: true,
				validType: 'cpu'
			});
			
			$('#server_mem').validatebox({
				//required: true,
				validType: 'mem'
			});
			
			$('#server_disk').validatebox({
				//required: true,
				validType: 'disk'
			});
			
			$('#server_power').validatebox({
				//required: true,
				validType: 'power'
			});
			
			$('#server_ethernet').validatebox({
				//required: true,
				validType: 'ethernet'
			});
						
		});
</script>

<div style="padding: 5px;">
	<form method="post">
		<table class="tableForm" id="tb" name="tb" >
			<tr>
                  <th style="width:80px;">机房机柜</th>
                  <td>
                  	<input style="line-height:26px;border:1px solid #ccc;width:130px" class="easyui-combobox" 
                        name="computerroom_id" id="computerroom_id" />                    
                    <input style="line-height:26px;border:1px solid #ccc;width:140px" class="easyui-combobox" 
                        name="rackspace_id" id="rackspace_id" />
                  </td>
			</tr>
            <tr>
				<th style="width: 80px;">设备型号</th>
				<td>
               		<input style="line-height:26px;border:1px solid #ccc;width:130px" class="easyui-combobox" 
                        name="hardware_manufacturer" id="hardware_manufacturer" />                    
                    <input style="line-height:26px;border:1px solid #ccc;width:140px" class="easyui-combobox" 
                        name="hardware_name" id="hardware_name" />
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">序列号</th>
				<td><input name="server_sn" class="easyui-validatebox" data-options="required:'true'" style="width: 400px;" />
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">资产编号</th>
				<td><input name="server_asset_tag" class="easyui-validatebox" data-options="required:'true'" style="width: 400px;" />
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">设备U数</th>
				<td><input name="server_height" class="easyui-numberbox" data-options="required:'true',min:1,max:99" style="width: 400px;" />
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">主机名</th>
				<td><input name="system_hostname" class="easyui-validatebox" style="width: 400px;" />
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">是否包含CDROM</th>
				<td><select id="server_cdrom" class="easyui-combobox" name="server_cdrom" style="width:200px;" data-options="required:true,panelHeight:'auto'">
                        <option value="0">否</option>
                        <option value="1">是</option>
                	</select>
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">RAID卡型号</th>
				<td><input name="server_raidtype" class="easyui-validatebox" style="width: 400px;" />
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">保修状态</th>
				<td><input id="server_warranty" class="easyui-combobox" name="server_warranty" style="width:200px;"/>
				</td>
			</tr>
            <tr id="tr_server_warranty_datetime" style='display: none'>
				<th style="width: 80px;">保修到期日</th>
				<td>
                <input class="easyui-datetimebox" id="server_warranty_datetime" name="server_warranty_datetime" 
        data-options="showSeconds:false" style="width:150px">
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">采购价格</th>
				<td><input name="server_price" class="easyui-numberbox" data-options="min:1,precision:2" style="width: 400px;" />
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">采购负责人</th>
				<td><input name="server_purchasing_director" class="easyui-validatebox" style="width: 400px;" />
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">采购日期</th>
				<td>
                <input class="easyui-datetimebox" name="server_buy_datetime" 
        data-options="showSeconds:false" style="width:150px">
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">cpu信息</th>
				<td><input id="server_cpu" name="server_cpu" style="width: 300px;" /><a class="server_cpu_add"><img src='{{=url_for_static('images/add.png')}}' style='border: 0px; width: 16px; height: 16px' />增加</a> 格式：型号*频率*物理数
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">内存信息</th>
				<td><input id="server_mem" name="server_mem" style="width: 300px;" /><a class="server_mem_add"><img src='{{=url_for_static('images/add.png')}}' style='border: 0px; width: 16px; height: 16px' />增加</a> 格式：型号*频率*单条容量*数量
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">硬盘信息</th>
				<td><input id="server_disk" name="server_disk" style="width: 300px;" /><a class="server_disk_add"><img  src='{{=url_for_static('images/add.png')}}' style='border: 0px; width: 16px; height: 16px' />增加</a> 格式：型号*转速*单盘容量*数量
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">电源信息</th>
				<td><input id="server_power" name="server_power" style="width: 300px;" /><a class="server_power_add"><img  src='{{=url_for_static('images/add.png')}}' style='border: 0px; width: 16px; height: 16px' />增加</a> 格式：型号*功率*数量
				</td>
			</tr>
            <tr>
				<th style="width: 80px;">网卡信息</th>
				<td><input id="server_ethernet" name="server_ethernet" style="width: 300px;" /><a class="server_ethernet_add"><img  src='{{=url_for_static('images/add.png')}}' style='border: 0px; width: 16px; height: 16px' />增加</a> 格式：型号*数量
				</td>
			</tr>
			<tr>
                  <th style="width:80px;">状态信息</th>
                  <td>
                  <input style="line-height:26px;border:1px solid #ccc;width:130px" class="easyui-combobox" 
                        name="hardwarestatus_id" id="hardwarestatus_id" />
                  </td>
			</tr>
            <tr id="tr_applicationtype_id" style='display: none'>
				<th style="width: 80px;">应用主题</th>
				<td>
                <input style="line-height:26px;border:1px solid #ccc;width:100px" class="easyui-combobox" 
                        name="department_id" id="department_id" />                    
                <input style="line-height:26px;border:1px solid #ccc;width:130px" class="easyui-combobox" 
                        name="departmentproject_id" id="departmentproject_id" />
                <input style="line-height:26px;border:1px solid #ccc;width:130px" class="easyui-combobox" 
                		id="applicationtype_id" name="applicationtype_id"/>
				</td>
			</tr>
            <!--
			<tr>
                  <th style="width:80px;">状态信息</th>
                  <td>
                  <input style="line-height:26px;border:1px solid #ccc;width:200px" class="easyui-combobox" 
                        name="hardwarestatus_id"
                        data-options="
                        url:'/devicespost/hardwarestatusinfo',
                        valueField:'id',
                        textField:'hardwarestatus_name',
                        editable:false,
                        required:true,
                        panelHeight:'150'
                    " />
                  </td>
			</tr>
			<tr>
                  <th style="width:80px;">应用主题</th>
                  <td>
                  <input style="line-height:26px;border:1px solid #ccc;width:200px" class="easyui-combobox" 
                        name="applicationtype_id"
                        data-options="
                        url:'/operationpost/applicationtypeinfo',
                        valueField:'id',
                        textField:'applicationtype_name',
                        editable:false,
                        required:true,
                        panelHeight:'150'
                    " />
                  </td>
			</tr>-->
            <tr>
				<th style="width: 80px;">备注</th>
				<td colspan="3"><textarea name="comment" style="height: 50px;width: 97%;"></textarea>
				</td>
			</tr>          
		</table>
	</form>
</div>